import editorWorker from "monaco-editor-core/esm/vs/editor/editor.worker?worker";
import vueWorker from "monaco-volar/vue.worker?worker";
import * as onigasm from "onigasm";
import onigasmWasm from "onigasm/lib/onigasm.wasm?url";


let succesful = false;


export function loadOnigasm() {
    return new Promise((resolve, reject) => {
        if (succesful) {
            resolve();
        } else {
            onigasm.loadWASM(onigasmWasm).then(res => {
                resolve(res);
            });
        }
    }).then(() => {
        succesful = true
    })
}

export function loadMonacoEnv() {
    window.MonacoEnvironment = {
        async getWorker(_, label) {
            if (label === "vue") {
                return new vueWorker();
            }
            return new editorWorker();
        },
    };
}
